package com.yuyu.service.impl;

import com.yuyu.dao.UserMapper;
import com.yuyu.entity.JiaoYi;
import com.yuyu.entity.User;
import com.yuyu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {


    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> getList() {
        return userMapper.getList();
    }

    @Override
    public void panduan(List<User> users) {


        double maney = 0.0;
        //一个规则判断
        for (int i = 0;i<users.size();i++){

            User user = users.get(i);
            List<JiaoYi> dates = user.getDates();
            for (int j = 0;j<users.size();j++){
                JiaoYi jiaoYi = dates.get(j);
                maney+=jiaoYi.getMoney();
            }
            if (maney>5000){

                user.setAge((int)maney);
              int a =  userMapper.add(user);
                maney = 0.0;
            }else{

                maney = 0.0;
            }
        }
    }
}
